﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Model.Admin.Order
{
    public class Order
    {
        public string conn = ConfigurationManager.ConnectionStrings["OnlineFloralShopConnection"].ConnectionString;
        DataTable dt;

        public DataTable lisorder()
        {
            return Common.DataAccess.GetData(null, null, "GetAllOrder");
        }
        public void FillListView(ListView list, DataTable dt)
        {
            list.DataSource = dt;
            list.DataBind();

        }
        // this is method used to  delete selected customer from listview 

        public DataTable selectById(String id)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "selectOrder_By_OrderId";
                cm.Parameters.Add("@OrderId", SqlDbType.NVarChar);
                cm.Parameters["@OrderId"].Value = id;
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataTable tble = new DataTable();
                da.Fill(tble);
                return tble;

            }

        }

        //=================================================================================
        public DataTable searchOrderByCusName(String username)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SearchOrderByCusName";
                cm.Parameters.Add("@Name", SqlDbType.NVarChar);
                cm.Parameters["@Name"].Value = username;
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataTable tble = new DataTable();
                da.Fill(tble);
                return tble;

            }
        }

        //=====================================================================================
        public DataTable SearhOrderByfilter(string sql)
        {
            SqlConnection con = new SqlConnection(conn);
            dt = new DataTable();
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(cm);
                da.Fill(dt);
                return dt;
            }
        }
        public DataTable getOrderOfCus(string UserName)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "getOrderOfCus";
                cm.Parameters.Add("@UserName", SqlDbType.NVarChar);
                cm.Parameters["@UserName"].Value = UserName;
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataTable tble = new DataTable();
                da.Fill(tble);
                return tble;

            }
        }
        //====================
        public DataTable getProductOfOrder(string OrderId)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "GetProductInOrder";
                cm.Parameters.Add("@OrderId", SqlDbType.NVarChar);
                cm.Parameters["@OrderId"].Value = OrderId;
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataTable tble = new DataTable();
                da.Fill(tble);
                return tble;

            }
        }
    }

}